<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_customer_category".
 *
 * @property string $id
 * @property integer $parentid
 * @property string $name
 */
class BusinessCustomerCategory extends \yii\db\ActiveRecord
{


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '大客户分类',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_customer_category';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['parentid'], 'integer'],
            [['name'], 'string', 'max' => 255],
            [['name'],'unique'],
        ];
    }



    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parentid' => '上级',
            'name' => '分类名称',
        ];
    }


    public function getParent()
    {
        return $this->hasOne(self::className(),['id'=>'parentid']);
    }

    public static function allCate()
    {
        return BusinessCustomerCategory::find()->asArray()->all();
    }

}
